package com.gec.system.controller;


import com.gec.system.config.OssTemplate;
import com.gec.system.config.VodTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class UploadController {
    @Autowired
    private OssTemplate ossTemplate;
    @Autowired
    private VodTemplate vodTemplate;
    @RequestMapping("/admin/upload/image")
    public String uploadImage(MultipartFile uploadImage){
        String url="";
        try {
            url = this.ossTemplate.upload(uploadImage.getOriginalFilename(), uploadImage.getInputStream());
            System.out.println(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return url;
    }
    @RequestMapping("/admin/upload/video")
    public String uploadVideo(MultipartFile uploadVideo){
        String id = "";
        try {
             id = this.vodTemplate.uploadVideo(uploadVideo.getOriginalFilename(), uploadVideo.getInputStream());
            System.out.println(id);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return id;
    }
}
